package com.cn.sl.server.config.jpa

import cn.dev33.satoken.spring.SpringMVCUtil
import cn.dev33.satoken.stp.StpUtil
import org.springframework.context.annotation.Configuration
import org.springframework.data.domain.AuditorAware
import java.util.*

@Configuration
class JpaAuditorConfig : AuditorAware<Long> {
    override fun getCurrentAuditor(): Optional<Long> {
        return Optional.of(
            if (SpringMVCUtil.isWeb()) {
                StpUtil.getLoginIdAsLong()
            } else {
                1L
            }
        )
    }
}